//
//  NILinksButton.m
//  HavalConnect
//
//  Created by nanding on 17/5/29.
//  Copyright © 2017年 mengy. All rights reserved.
//

#import "NILinksButton.h"
#import "ColorDefine.h"
#import "FontDefines.h"

@implementation NILinksButton
- (instancetype)init
{
    self = [super init];
    if (self) {
    }
    return self;
}


- (void) drawRect:(CGRect)rect {
    
    [super drawRect:rect];
    
    if (_showLink) {
        CGRect textRect = self.titleLabel.frame;
        CGContextRef contextRef = UIGraphicsGetCurrentContext();
        
        CGFloat descender = self.titleLabel.font.descender;
        if([NIColorLinkButtonColor isKindOfClass:[UIColor class]]){
            CGContextSetStrokeColorWithColor(contextRef, NIColorLinkButtonColor.CGColor);
        }
        
        CGContextMoveToPoint(contextRef, textRect.origin.x, textRect.origin.y + textRect.size.height + descender+1);
        CGContextAddLineToPoint(contextRef, textRect.origin.x + textRect.size.width, textRect.origin.y + textRect.size.height + descender+1);
        
        CGContextClosePath(contextRef);
        CGContextDrawPath(contextRef, kCGPathStroke);
    }
    
    [self setTitleColor:NIColorLinkButtonColor forState:UIControlStateNormal];
    [self.titleLabel setFont:NIFontLinkButtonTitleFont];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
